package com.zhongkun.controller;

import com.zhongkun.pojo.*;
import com.zhongkun.service.FileMapperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


@Controller
@RequestMapping("/file")
public class FileController extends BaseController{

    @Autowired
    private FileMapperService fileMapperService;

    //获取主页的各种数据
    @RequestMapping("/mainAfterLogin")
    public ModelAndView getUserProfile(){
        session = request.getSession();

        //主页的所有动态
        List<UserShare> userShareTime = fileMapperService.getAllShareByTime();
        System.out.println("找到"+userShareTime.size()+"条动态"+"最新的一条编号为:"+userShareTime.get(0).getId());
        session.setAttribute("share",userShareTime);

        /*所登录用户 获得他一切可以在网页上显示的信息*/
        User user = (User)session.getAttribute("userLogin");
        //头像path
        Picture profile = fileMapperService.getProfile(user);
        user.setProfilePath(profile.getPath());
        //属于该用户的所有动态
        List<UserShare> userShareList = new ToolUtil().getUserShareById(user.getId(),userShareTime);
        System.out.println(user);


        //主页左侧的热门内容
        List<UserShare> userShareHot = fileMapperService.getAllShareByHot();
        System.out.println("找到"+userShareTime.size()+"条动态"+"最火的一条编号为:"+userShareHot.get(0).getId());
        session.setAttribute("shareHot",userShareHot);

        //获取图库
        List<Picture> pictureList = fileMapperService.getAllPicture();
        System.out.println("图库有"+pictureList.size()+"张图:\n"+pictureList);
        session.setAttribute("allPicture",pictureList);

        //获取所有的评论
        List<Comment> commentList = fileMapperService.getAllShareCommentByTime();
        System.out.println("评论区有"+commentList.size()+"条评论:\n"+commentList);
        session.setAttribute("allComment",commentList);

        return new ModelAndView("/mainAfterLogin");
    }



}
